<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>addClass</title>
    <style>
        div{
            height: 100px;
            width: 100px;
            border: 1px solid #243f99;
        }

        .red{
            background: red;
        }

        .blue{
            background: blue;
        }
    </style>
    <script src="../../js/jquery.1.8.3.min.js"></script>
    <script>
        $(function () {
            $("#btn1").click(function () {
                $("div").removeClass("blue");
                $("div").addClass("red");
                console.log($("div").attr("class"));
            });

            $("#btn2").click(function () {
                $("div").removeClass("red");
                $("div").addClass("blue");
                console.log($("div").attr("class"));
            });

            $("#btn3").click(function () {
                $("div").toggleClass("red");
            });

            $("#btn4").click(function () {
                $("div").toggleClass("blue");
            });
        })
    </script>
</head>
<body>
    <div></div>
    <button id="btn1">红色</button>
    <button id="btn2">蓝色</button>
    <button id="btn3">toggleClass红色</button>
    <button id="btn4">toggleClass蓝色</button>
</body>
</html>